package tieba.sign.execute;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import tieba.core.TBApi;
import tieba.entity.TbSignTask;
import tieba.service.ITbSignTaskService;
import cl.tools.http.method.BasicMethod;

public class SignAction {

	private final List<TbSignTask> tasks;
	private final ITbSignTaskService tbSignTaskService;

	public SignAction(List<TbSignTask> tasks,
			ITbSignTaskService tbSignTaskService) {
		super();
		this.tasks = tasks;
		this.tbSignTaskService = tbSignTaskService;
	}

	public SignAction(TbSignTask task, ITbSignTaskService tbSignTaskService) {
		super();
		this.tasks = new ArrayList<TbSignTask>();
		tasks.add(task);
		this.tbSignTaskService = tbSignTaskService;
	}

	public void execute() {
		new Thread(new Runnable() {
			@Override
			public void run() {

				for (TbSignTask task : tasks) {
					task.setExeTime(new Date());
					task.setExeStatus(1);
					String bduss = task.getTbUser() == null ? null : task
							.getTbUser().getBduss();
					String body = null;
					try {
						body = BasicMethod.get(TBApi.SIGN + "/" + bduss)
								.asString();
					} catch (Exception e) {
						task.setExeStatus(2);
					}
					System.out.println(body);
				}
			}
		}).start();
	}
}
